package com.kuaiying.kuai.ying.model.print_file;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.kuaiying.kuai.ying.model.user.UserModel;

public class PrintfileModel extends Model<PrintfileModel>{

	private static final long serialVersionUID = -6984293973714614241L;
	
	public static final PrintfileModel me = new PrintfileModel();
	
	private static final String USER_CACHE = "print_file";
	
	public PrintfileModel(){
		super( );
	}
	/**
	 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
	 */
	public Page<PrintfileModel> paginate(int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select *", "from  print_file order by id asc");
	}
	
	/**
	 * 根據用戶名和用戶密碼驗證用戶是否存在
	 * @param userName：用戶名
	 * @param pwd：用戶密碼
	 * @return：用戶信息或null
	 */
	public PrintfileModel getUserByNameAndPwd(String userName, String pwd){
		String sql = "select * from print_file where name = '" + userName + "' and password ='" +  pwd + "'" ;
		System.out.println( sql );
		
		PrintfileModel user = me.findFirst(sql);
		
		return user;
	}
	
	public boolean updatePrintfile(Integer user_id,String filename, String pathyuan){
		PrintfileModel user = new PrintfileModel();
		user.set("name", filename);
		user.set("user_id", user_id);
		user.set("path_yuan", pathyuan);
		return user.save();
	}

	public PrintfileModel getFileid(Integer user_id,String filename, String pathyuan){
		PrintfileModel user = new PrintfileModel();
		user.set("name", filename);
		user.set("user_id", user_id);
		user.set("path_yuan", pathyuan);
		pathyuan = pathyuan.replaceAll( "\\\\",   "\\\\\\\\");
		String sql = "select * from print_file where user_id = " + user_id + " and name ='" +  filename + "' and path_yuan ='" +  pathyuan + "'" ;
		System.out.println(sql);
		System.out.println(pathyuan);
		return user.findFirst(sql);
	}


}


